package com.javabasic.algorithm.leetcode;

import java.util.Arrays;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/7/11 22:50
 * @Version 1.0
 **/
public class RangeSumOfSortedSubarraySums {

    final int MOD = 1000000007;
    public int rangeSum(int[] nums, int n, int left, int right) {
        int[] sum = new int[n*(n+1)/2+1];
        int k = 1;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (j == i) {
                    sum[k++] = nums[i];
                    continue;
                }
                sum[k++] = sum[k-1] + nums[j];
            }
        }
        Arrays.sort(sum);
        for (int i = 1; i <= sum.length; i++) {
            System.out.print(sum[i] + " ");
        }
        System.out.println();
        int result = 0;
        for (int i = left; i <= right; i++) {
            result = (result + sum[i])%MOD;
        }
        return result;
    }

}
